package com.youlai.system.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youlai.system.converter.SalaryConverter;
import com.youlai.system.mapper.SalaryMapper;
import com.youlai.system.mapper.SalaryMapper;
import com.youlai.system.model.entity.Salary;
import com.youlai.system.model.entity.Salary;
import com.youlai.system.model.entity.Salary;
import com.youlai.system.model.form.SalaryForm;
import com.youlai.system.model.form.SalaryForm;
import com.youlai.system.model.query.SalaryQuery;
import com.youlai.system.model.vo.SalaryVO;
import com.youlai.system.service.SalaryService;
import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Data
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements SalaryService {
    private final SalaryMapper salaryMapper;
    private final SalaryConverter salaryConverter;
    @Override
    public PageInfo<SalaryVO> getSalaryList(SalaryQuery queryParams) {
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Integer keyword = queryParams.getKeyword();

        PageHelper.startPage(pageNum, pageSize);
        List<SalaryVO> list = salaryMapper.selectSalaryAll(keyword);

        return new PageInfo<SalaryVO>(list);
    }

    @Override
    public Integer UpdateSalary(SalaryForm salaryForm) {
        Salary entity = salaryConverter.form2Entity(salaryForm);
        boolean result = salaryMapper.updateSalary(entity);
        Assert.isTrue(result,"社保保存失败");
        return 0;
    }

    @Override
    public SalaryVO selectById(Integer id) {
        SalaryVO salaryVO=salaryMapper.selectById(id);
        return salaryVO;
    }

    @Override
    public boolean addSalary(SalaryForm salaryForm) {
        Salary entity = salaryConverter.form2Entity(salaryForm);
        boolean result = salaryMapper.addSalary(entity);
        Assert.isTrue(result,"工资保存失败");
        return result;
    }

    @Override
    public boolean deleteSalary(Integer id) {
        boolean result = salaryMapper.deleteSalary(id);
        return result;
    }
}
